<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/5/11
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>">
    <title>Title</title>
    <script type="text/javascript" src="webjars/jquery/3.2.0/jquery.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

</head>
<style>
    input{
        display: inline-block;
    }
</style>
<body>
<form action="" method="post" id="deptForm" class="form-horizontal">
    <input type="hidden" name="id" value="${dept.id}">
    <div class="form-group">
        <label class="col-sm-2 control-label">上级部门：</label>
            <div class="col-sm-10">
            <input type="text" style="width: 50%" name="parentId" class="form-control" value="${dept.parentId}">
            </div>
        </div>
    <div class="form-group">
        <label  class="col-sm-2 control-label">部门名称：</label>
        <div class="col-sm-10">
        <input type="text" style="width: 50%" name="deptName" class="form-control" value="${dept.deptName}">
        </div>
        </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">显示顺序:</label>
        <div class="col-sm-10">
        <input type="number" style="width: 50%" name="sort" class="form-control" value="${dept.sort}">
        </div>
        </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">负责人:</label>
        <div class="col-sm-10">
        <input type="text" style="width: 50%" name="chargeName" class="form-control" value="${dept.chargeName}">
        </div>
        </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">联系电话:</label>
        <div class="col-sm-10">
        <input type="text" style="width: 50%" name="phone" class="form-control" value="${dept.phone}">
        </div>
        </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">邮箱:</label>
        <div class="col-sm-10">
        <input type="email" style="width: 50%" name="email"class="form-control" value="${dept.email}">
        </div>
    </div>
    <br>
    <div class="form-group">
        <label class="col-sm-2 control-label">部门状态:</label>
        <div class="col-sm-10">
       <input type="radio"  value="0" name="status" <c:if test="${dept.status==0}"> checked</c:if>>正常
        <input type="radio"  value="1" name="status" <c:if test="${dept.status==1}">checked</c:if>>停用
        </div>
        </div>
    <div class="form-group">
        <div class="col-sm-12" style="text-align: center">
        <input type="button" class="btn btn-primary" value="保存" onclick="save();">
        </div>
    </div>
</form>
</body>
<script>
    function save(){
        // 将form表单中的数据发请求到后端
       var data = $("#deptForm").serialize();
        $.ajax({
            url:'dept/save',
            type:'post',
            data:data,
            success:function(ret){
                if(ret){
                    alert('操作成功')
                    document.location.href="dept/list"
                }else{
                    alert('操作失败')
                }
            }
        })

    }
</script>
</html>
